 const retryAdapterEnhancer=(adapter, options)=> {
    //  全局配置的times和delay 并设置默认值
    const { times:__times = 0, delay:__delay = 300 } = options;
    return async (config) => {
        // 局部设置的重试次数和重试延迟时间
        // 优先使用局部的设置 再取全局设置
      const { times = __times, delay:_delay = __delay } = config;
      let __retryCount = 0;
      const request = async () => {
        try {
          return await adapter(config);
        } catch (err) {
          // 判断是否进行重试
          if (!times || __retryCount >= times) {
            return Promise.reject(err);
          }
          __retryCount++; // 增加重试次数
          // 延时处理
          const delay = new Promise((resolve) => {
            setTimeout(() => {
              resolve();
            }, _delay);
           });
           // 重新发起请求
           return delay.then(() => {
             return request();
           });
          }
        };
     return request();
    };
  }
  
  export {retryAdapterEnhancer}